import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ShoppingSystem {
    public static void main(String[] args) {
        List<RegularUser> users = new ArrayList<>();
        List<Product> products = new ArrayList<>();
        UserManager userManager = new UserManager();
        AdminManager adminManager = new AdminManager();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("欢迎来到购物系统");
            System.out.println("1. 用户注册");
            System.out.println("2. 登录");
            System.out.println("3. 退出");
            System.out.print("请选择操作: ");
            int choice = scanner.nextInt();
            scanner.nextLine(); // 消耗换行符

            switch (choice) {
                case 1:
                    userManager.registerUser(users, scanner);
                    break;
                case 2:
                    System.out.print("是否为管理员登录? (y/n): ");
                    String isAdmin = scanner.nextLine();
                    if (isAdmin.equalsIgnoreCase("y")) {
                        if (adminManager.adminLogin(scanner)) {
                            adminManager.adminFunctionality(users, products, scanner);
                        } else {
                            System.out.println("管理员登录失败。");
                        }
                    } else {
                        RegularUser user = userManager.loginUser(users, scanner);
                        if (user != null) {
                            userManager.userFunctionality(user, products, scanner);
                        } else {
                            System.out.println("用户登录失败。");
                        }
                    }
                    break;
                case 3:
                    System.out.println("退出系统。");
                    scanner.close();
                    return;
                default:
                    System.out.println("无效的选择。");
            }
        }
    }
}

